﻿using System;
using System.Net;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WorldDomination.Net;


namespace WorldDomination.Test
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class IPAddressExtensionsTest
    {
        private static string[] _ipv4List = {
            "59.167.135.163",
            "144.140.154.69",
            "147.132.42.18",
            "207.46.197.32",
            "64.233.187.99",
            "203.26.51.42"
        };

        private static string[] _countryList = {
            "AUSTRALIA",
            "AUSTRALIA",
            "AUSTRALIA",
            "UNITED STATES",
            "UNITED STATES",
            "AUSTRALIA"
        };

        private static string[] _iso3166TwoLetterCodeList = {
            "AU",
            "AU",
            "AU",
            "US",
            "US",
            "AU"
        };
                                        

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        [TestMethod]
        public void CountryTest()
        {
            IPAddress ipAddress;
            string result;


            for (int i = 0; i < IPAddressExtensionsTest._ipv4List.Length; i++)
            {
                if (IPAddress.TryParse(IPAddressExtensionsTest._ipv4List[i], 
                    out ipAddress))
                {
                    result = ipAddress.Country();
                    Assert.IsTrue(!string.IsNullOrEmpty(result));
                    Assert.IsTrue(result.StartsWith(IPAddressExtensionsTest._countryList[i]));
                }
                else
                {
                    Assert.Fail("Ipv4Address [" + IPAddressExtensionsTest._ipv4List[i] + "] failed to be converted into an IPAddress object.");
                }
            }
        }

        [TestMethod]
        public void Iso3166TwoLetterCodeTest()
        {
            IPAddress ipAddress;
            string result;


            for (int i = 0; i < IPAddressExtensionsTest._ipv4List.Length; i++)
            {
                if (IPAddress.TryParse(IPAddressExtensionsTest._ipv4List[i],
                    out ipAddress))
                {
                    result = ipAddress.Iso3166TwoLetterCode();
                    Assert.IsTrue(!string.IsNullOrEmpty(result));
                    Assert.IsTrue(result.StartsWith(IPAddressExtensionsTest._iso3166TwoLetterCodeList[i]));
                }
                else
                {
                    Assert.Fail("Ipv4Address [" + IPAddressExtensionsTest._ipv4List[i] + "] failed to be converted into an IPAddress object.");
                }
            }
        }
    }
}